package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CheckInOut;
import com.ruoyi.system.service.ICheckInOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入住/退房Controller
 * 
 * @author txy
 * @date 2022-02-09
 */
@RestController
@RequestMapping("/system/check")
public class CheckInOutController extends BaseController
{
    @Autowired
    private ICheckInOutService checkInOutService;

    /**
     * 查询入住/退房列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckInOut checkInOut)
    {
        startPage();
        List<CheckInOut> list = checkInOutService.selectCheckInOutList(checkInOut);
        return getDataTable(list);
    }

    /**
     * 导出入住/退房列表
     */
    @PreAuthorize("@ss.hasPermi('system:check:export')")
    @Log(title = "入住/退房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckInOut checkInOut)
    {
        List<CheckInOut> list = checkInOutService.selectCheckInOutList(checkInOut);
        ExcelUtil<CheckInOut> util = new ExcelUtil<CheckInOut>(CheckInOut.class);
        util.exportExcel(response, list, "入住/退房数据");
    }

    /**
     * 获取入住/退房详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:check:query')")
    @GetMapping(value = "/{roomId}")
    public AjaxResult getInfo(@PathVariable("roomId") Long roomId)
    {
        return AjaxResult.success(checkInOutService.selectCheckInOutByRoomId(roomId));
    }

    /**
     * 新增入住/退房
     */
    @PreAuthorize("@ss.hasPermi('system:check:add')")
    @Log(title = "入住/退房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckInOut checkInOut)
    {
        return toAjax(checkInOutService.insertCheckInOut(checkInOut));
    }

    /**
     * 修改入住/退房
     */
    @PreAuthorize("@ss.hasPermi('system:check:edit')")
    @Log(title = "入住/退房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckInOut checkInOut)
    {
        return toAjax(checkInOutService.updateCheckInOut(checkInOut));
    }

    /**
     * 删除入住/退房
     */
    @PreAuthorize("@ss.hasPermi('system:check:remove')")
    @Log(title = "入住/退房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roomIds}")
    public AjaxResult remove(@PathVariable Long[] roomIds)
    {
        return toAjax(checkInOutService.deleteCheckInOutByRoomIds(roomIds));
    }
}
